//


#import "NT_CustomTabBar.h"
#import "NT_WaitDoViewController.h"
#import "NT_MainViewController.h"
#import "NT_SetViewController.h"
#import "NT_AddressViewController.h"

//
@interface NT_CustomTabBar ()<NT_TabbarDelegate>

@end

@implementation NT_CustomTabBar

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createTabBar];//创建标签栏
    [self createSubviewControllers];//创建子控制器
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hidden) name:@"Hidden" object:nil];//观察隐藏tabbar
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Appear) name:@"Appear" object:nil];//观察显示tabbar
    
}
//隐藏tabbar
- (void)Hidden{
    self.tabBarV.hidden = YES;
}
//显示tabbar
- (void)Appear{
    self.tabBarV.hidden = NO;
}

//创建标签栏
- (void)createTabBar{
    self.tabBar.hidden = YES;
    
    NSArray * imgNormal = @[@"home1", @"book1",@"address1",@"set"];
    NSArray * imgSelected = @[@"home2", @"book2",@"address2",@"set2"];
    NSArray * buttonTitle = @[@"Home", @"Wait",@"Book",@"Set",];
    
    __weak typeof(self) weakself=self;
    NSDictionary * dic = [[NSDictionary alloc]initWithObjectsAndKeys:imgNormal,@"imageNameNormal",imgSelected,@"imageNameSelected",buttonTitle,@"buttonTitle", nil];
    NSInteger currentIndex = self.selectedIndex;
    self.tabBarV = [[NT_Tabbar alloc]initWithFrame:CGRectMake(0,kMainScreenHeight-UI_TAB_BAR_HEIGHT,kMainScreenWidth, UI_TAB_BAR_HEIGHT) andTabBarButtonDictory:dic andBlock:^(NSInteger index) {
        weakself.selectedIndex = index;
        if (currentIndex != weakself.selectedIndex) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"popView" object:nil userInfo:nil];
        }
    }];
    self.tabBarV.delegate = self;
    [self.view addSubview:self.tabBarV];
    
}

//构建子视图控制器
- (void)createSubviewControllers{
    
    //创建子控制器
    NT_MainViewController * v1 = [[NT_MainViewController alloc] init];
    NT_WaitDoViewController *v2 = [[NT_WaitDoViewController alloc] init];//
    NT_AddressViewController *v3 = [[NT_AddressViewController alloc]init];
    NT_SetViewController *v4 = [[NT_SetViewController alloc]init];
    //创建子控制器的导航栏控制器
    UINavigationController *nv1 = [[UINavigationController alloc] initWithRootViewController: v1];
    UINavigationController *nv2 = [[UINavigationController alloc] initWithRootViewController: v2];
    UINavigationController *nv3 = [[UINavigationController alloc] initWithRootViewController: v3];
    UINavigationController *nv4 = [[UINavigationController alloc] initWithRootViewController: v4];
    self.viewControllers =@[nv1,nv2,nv3,nv4];
    
}

@end
